<div style="margin:10px" class="div_form_content">
    <div >
    <h1>Knowledge bases</h1>
    <table>
        <tr>
            <td>
                Choose category: 
                <select name="category" id="category" class="select">
                        <option value="0">- Select category - </option>
                        <?foreach($structure as $c) :?>
                        <?
                        $id=$c['id']; $sep=str_repeat("&nbsp;&nbsp;&nbsp;",($c['level']))."|__";
                        $selected=(($id==$catid)?'selected':'');
                        ?>
                        <option value="<?=$id?>" <?=$selected?>><?=$sep?><?=$categories[$id]['name']?></option>
                        
                        <?endforeach?>
                </select>
            </td>
            <td>
                <div style="float:right; margin-right: 30px;">
                    
                    <input type="text" id="search" value="<?=$s?>" />
                    <input type ="button" value="search" onclick="search()"/>
                </div>
            </td>
        </tr>
        <br>
    </table>

    <?foreach($posts as $u):?>
         <div class="article" >
            <h3><a href="index.php?m=manage_solution&a=view&sid=<?=$u['idsolutions']?>"><?=$u['title']?></a> </h3>
            <div class="article-hearder">
                <span style="margin-left:100px; font-size: 12px;color: #aaa;float: right">
                    <label><img src="../images/view.png" ><b> <?=$u['view']?></b></label>
                    -
                    <label><img src="../images/comment.png" > <b><?=$u['comment']?></b></label>
                </span>
            </div>
            <div class="article-single">
            <span><?=substr($u['detail'],0,200)."...";?></span>
            </div>
            <div class="article-footer">

                <div class="user-details">
                    <?$time=elapsed_time($u['ctime']);?>
                            <div  id ="user-info">
                                <span style="color: #aaa" title="Posted in"><b>posted <?=$time?> by</b></span>
                                <a href="" style="text-decoration: none"><b><?=$u['user_name']?></b></a><br>

                            </div>
                </div>
                <div style="clear: both"></div>
            </div>

        </div><!--div article-->

   <?endforeach?>

    
    </div>
    
    <br>

<div id="page-number">
    <div id="page-number-left">
        Page 
        <?if($num_pages<=5):?> <!--11111so trang < 5 in tu 1 den 5-->
            <?for($i=1;$i<=$num_pages;$i++):?>
            <span style="border: 1px solid #eee; padding: 5px;<?=$style=($i==$page_num)?'background-color: #ddd':'';?>" class="span_page_number" title="<?=$i?>"><?=$i?></span>
            <?endfor?>
        <?else:?>

            <?if($page_num<5):?> <!--222222222-so trang > 5  neu trang hienj tai <5 in tu 1 den 5-->
				
                <?for($i=1;$i<=5;$i++):?>
                <span style="border: 1px solid #eee; padding: 5px;<?=$style=($i==$page_num)?'background-color: #ddd':'';?>" class="span_page_number" title="<?=$i?>"><?=$i?></span>
                <?endfor?>
                <span style="border: 1px solid #eee; padding: 5px;">...</span>
                <span style="border: 1px solid #eee; padding: 5px;" class="span_page_number" title="<?=$num_pages?>"><?=$num_pages?></span>

            <?else:?> <!--so trang > 5  neu trang hienj tai >= 5 phải kiểm tra lại num_pages-->
                <?if($num_pages>$page_num+4):?>
					<span style="border: 1px solid #eee; padding: 5px;" class="span_page_number" title="1">1</span>
					<span style="border: 1px solid #eee; padding: 5px;">...</span>
                    <?for($i=$page_num-3;$i<=$page_num+3;$i++):?>
                    <span style="border: 1px solid #eee; padding: 5px;<?=$style=($i==$page_num)?'background-color: #ddd':'';?>" class="span_page_number" title="<?=$i?>"><?=$i?></span>
                    <?endfor?>
                    <span style="border: 1px solid #eee; padding: 5px;">...</span>
                    <span style="border: 1px solid #eee; padding: 5px;" class="span_page_number" title="<?=$num_pages?>"><?=$num_pages?></a></span>
                 <?else:?>
					<span style="border: 1px solid #ddd; padding: 5px;" class="span_page_number" title="1">1</span>
					<span style="border: 1px solid #ddd; padding: 5px;">...</span>
                    <?for($i=$page_num-3;$i<=$num_pages;$i++):?>
                    <span style="border: 1px solid #eee; padding: 5px;<?=$style=($i==$page_num)?'background-color: #ddd':'';?>" class="span_page_number" title="<?=$i?>"><?=$i?></span>
                    <?endfor?>
                  <?endif?>
            <?endif?> <!--222222222-so trang > 5  neu trang hienj tai <5 in tu 1 den 5-->
        <?endif?><!--11111so trang < 5 in tu 1 den 5-->

    </div>
</div>
</div>

<script>
function search(){
    var word=$('#search').val();
    var url="index.php?m=manage_solution&a=index&s="+word;
    window.location=url;
}

$("#category").change(function(){
    var c_id=$("#category").val();
	//var group= <?php echo($group);?>;
    //alert(word);
    var url="index.php?m=manage_solution&a=index";
    if(c_id!='0'){
        url=url+"&catid="+c_id;
    }
    //if(group!=""){
//        url=url+"&group="+group;
//    }
    
    window.location=url;
});

function deleteDevice(c_id){

    var conf = confirm("Are you sure you want to delete this customer?");
    if(conf == true){
         var url="index.php?m=manage_device&a=delete&d_id="+c_id;
         window.location=url;
         //alert (url);
    }

}
</script>

<style>
    table{
        width: 100%;
        margin: 10px;
        border-bottom: 1px solid #ddd;
        
    }
td
{
padding:3px;
}
</style>

<script>
    
    $('span.span_page_number').on('click', function() {
    var page = $(this).attr("title"); 
    Refresh(page); 

});
function Refresh(p){

    var url="index.php?m=manage_customer&a=index&p="+p;  

    window.location=url;
}   
</script>
